package com.pignest.hotel.beans;

import java.util.Date;

import com.pignest.framework.util.Utils;
import com.pignest.hotel.annotation.Bean;
import com.pignest.hotel.beans.global.BaseBean;
import com.pignest.hotel.definition.ChargeOpType;
import com.pignest.hotel.definition.PayMethod;
import com.pignest.hotel.util.DateUtil;

/**
 * (总台工作人员)值班
 * */
@Bean("值班")
public class Duty extends BaseBean {

	private static final long serialVersionUID = -6206464649248873594L;
	
	public static final int STATUS_ON_DUTY = 0;
	public static final int STATUS_OVER = 1;
	public static final int STATUS_PAUSE = 2;

	private User user;
	private User previousUser;
	private Date startTime;
	private Date endTime;
	
	private int startCash;			//开始时现金(交接)
	private int endCash;			//结束时现金
	private int bankCard;			//银行卡刷卡消费
	private int memberCard;			//会员卡余额消费
	private int recharge;			//会员卡充值
	
//	/**
//	 * 开始金额, 即从上一值班人员交接的金额<br/>
//	 * */
//	private int startAmount;		//所有金额(不含会员卡消费)
//	/**
//	 * 结束值班时的金额
//	 * */
//	private int endAmount;
//	private int startAmount2;		//信用卡
//	private int endAmount2;
//	private int startAmount3;		//借记卡
//	private int endAmount3;
//	private int startAmount4;		//会员卡
//	private int endAmount4;
	/**
	 * (财务)提取(+)或存入(-)金额
	 * */
	private int withdraw;
	/**
	 * 值班状态
	 */
	private int status;
	
	public Duty() {
	}
	
	public Duty(User user, User previous, int startCash) {
		this.user = user;
		this.previousUser = previous;
		this.endCash = this.startCash = startCash;
		this.status = STATUS_ON_DUTY;
		this.startTime = new Date();
	}
	
	public User getUser() {
		return user;
	}
	public void setUser(User user) {
		this.user = user;
	}
	public User getPreviousUser() {
		return previousUser;
	}
	public void setPreviousUser(User previousUser) {
		this.previousUser = previousUser;
	}
	public Date getStartTime() {
		return startTime;
	}
	public void setStartTime(Date startTime) {
		this.startTime = startTime;
	}
	public Date getEndTime() {
		return endTime;
	}
	public void setEndTime(Date endTime) {
		this.endTime = endTime;
	}
//	public int getStartAmount() {
//		return startAmount;
//	}
//	public void setStartAmount(int startAmount) {
//		this.startAmount = startAmount;
//	}
//	public int getEndAmount() {
//		return endAmount;
//	}
//	public void setEndAmount(int endAmount) {
//		this.endAmount = endAmount;
//	}
	public int getWithdraw() {
		return withdraw;
	}
	public void setWithdraw(int amount) {
		this.withdraw = amount;
	}
	public int getStatus() {
		return status;
	}
	public void setStatus(int status) {
		this.status = status;
	}
	
	
//	public int getStartAmount3() {
//		return startAmount3;
//	}
//
//	public void setStartAmount3(int startAmount3) {
//		this.startAmount3 = startAmount3;
//	}
//
//	public int getEndAmount3() {
//		return endAmount3;
//	}
//
//	public void setEndAmount3(int endAmount3) {
//		this.endAmount3 = endAmount3;
//	}
//
//	public int getStartAmount4() {
//		return startAmount4;
//	}
//
//	public void setStartAmount4(int startAmount4) {
//		this.startAmount4 = startAmount4;
//	}
//
//	public int getEndAmount4() {
//		return endAmount4;
//	}
//
//	public void setEndAmount4(int endAmount4) {
//		this.endAmount4 = endAmount4;
//	}
//	
//	public void setStartAmount2(int startAmount2) {
//		this.startAmount2 = startAmount2;
//	}
//
//	public void setEndAmount2(int endAmount2) {
//		this.endAmount2 = endAmount2;
//	}
//	
//	public int getEndAmount2() {
//		return endAmount2;
//	}
//	
//	public int getStartAmount2() {
//		return startAmount2;
//	}

	public int getStartCash() {
		return startCash;
	}

	public void setStartCash(int startCash) {
		this.startCash = startCash;
	}

	public int getEndCash() {
		return endCash;
	}

	public void setEndCash(int endCash) {
		this.endCash = endCash;
	}

	public int getMemberCard() {
		return memberCard;
	}

	public void setMemberCard(int memberCard) {
		this.memberCard = memberCard;
	}

	public int getBankCard() {
		return bankCard;
	}

	public void setBankCard(int bankCard) {
		this.bankCard = bankCard;
	}
	
	public int getRecharge() {
		return recharge;
	}
	
	public void setRecharge(int recharge) {
		this.recharge = recharge;
	}
	
	/////////////////////////////////////////////////////////////////
	
	/**
	 * 预备金
	 * */
	public void reserve(int money) {
		this.startCash += money;
		this.endCash += money;
	}
	
	public void finish() {
		status = STATUS_OVER;
		endTime = new Date();
	}
	
	public void receive(int money, ChargeOpType purpose, PayMethod method) {
		if (purpose == ChargeOpType.OnCharge) {
			recharge += money;
		}
		switch (method) {
		case CASH:
			endCash += money;
			break;
		case CREDIT_CARD:
		case DEBIT_CARD:
			bankCard += money;
			break;
		case MEMBER_CARD:
			memberCard += money;
			break;
		default:
			break;
		}
	}
	
	public void receive(int money, ChargeOpType purpose, PayMethod method, String desc) {
		if (purpose == ChargeOpType.OnCharge) {
			recharge += money;
		}
		switch (method) {
		case CASH:
			endCash += money;
			break;
		case CREDIT_CARD:
		case DEBIT_CARD:
			bankCard += money;
			break;
		case MEMBER_CARD:
			memberCard += money;
			break;
		default:
			break;
		}
	}
	
	public void pass(int money) {
		startCash += money;
		endCash += money;
	}
	
	public void withdraw(int money) {
		this.withdraw += money;
		this.endCash -= money;
	}
	
	public String getStatus2() {
		switch (status) {
		case STATUS_ON_DUTY:
			return "值班中";
		case STATUS_PAUSE:
			return "暂停";
		case STATUS_OVER:
			return "结束";
		default:
			break;
		}
		return null;
	}
	
	public String getStartTime2() {
		return DateUtil.toString(startTime, DateUtil.HOTEL_DEFAULT_FORMAT);
	}
	
	public String getEndTime2() {
		return endTime == null ? "" :DateUtil.toString(endTime, DateUtil.HOTEL_DEFAULT_FORMAT);
	}
	
	public String getAmounts() {
		StringBuilder sb = new StringBuilder();
		sb.append("<table class='normal'><tr>");
		sb.append("<th>起始现金</th>");
		if (status == STATUS_OVER)
			sb.append("<th>结束现金</th>");
		else
			sb.append("<th>当前现金</th>");
		sb.append("<th>银行卡消费</th>");
		sb.append("<th>会员卡消费</th>");
		sb.append("<th>会员充值</th>");
		sb.append("<th>财务提款</th>");
		sb.append("</tr><tr>");
		sb.append("<td>").append(Utils.toPrice(startCash)).append("</td>");
		sb.append("<td>").append(Utils.toPrice(endCash)).append("</td>");
		sb.append("<td>").append(Utils.toPrice(bankCard)).append("</td>");
		sb.append("<td>").append(Utils.toPrice(memberCard)).append("</td>");
		sb.append("<td>").append(Utils.toPrice(recharge)).append("</td>");
		sb.append("<td>").append(Utils.toPrice(withdraw)).append("</td>");
		sb.append("</tr></table>");
		return sb.toString();
	}
	
//	public String getStartAmount2() {
//		return Utils.toPrice(startAmount);
//	}
//	
//	public String getEndAmount2() {
//		return Utils.toPrice(endAmount);
//	}
	
	public String getPreviousUser2() {
		if (previousUser == null)
			return "";
		return previousUser.getName() + " (工号:" + previousUser.getWorkNumber() + ")";
	}
	
	@Override
	public String toSimpleString() {
		String previous = previousUser == null ? null : previousUser.getName();
		return concat(user.getName(), getStatus2(), previous, String.valueOf(endCash), String.valueOf(withdraw));
	}
}
